import React, { Component } from 'react'
import request from '../untils/request'

export default class Home extends Component {
    state={
        sum:0
    }
    //发送请求 获取签到天数
    componentDidMount(){
        this.getsum()
    }
    render() {
        let {sum}=this.state;
        return (
            <div>
                <button onClick={this.sign}>签到</button>
                签到天数:{sum}
            </div>
        )
    }

    sign=async ()=>{
        let res=await request.get('/sign',{params:{id:localStorage.uid}});
        alert(res.data.msg)
        if(res.data.code===0){
            this.getsum()
        }
    }

    getsum=async ()=>{
        let res=await request.get('/getsum',{params:{id:localStorage.uid}})
        this.setState({
            sum:res.data.sum===null?0:res.data.sum
        })
    }
}
